import request from './request';

/**
 * 获取所有成就
 * @param params 查询参数
 * @returns Promise
 */
export function getAchievements(params?: any) {
  return request({
    url: '/api/achievement/list',
    method: 'get',
    params
  });
}

/**
 * 获取特定类别的成就
 * @param category 成就类别
 * @returns Promise
 */
export function getAchievementsByCategory(category: string) {
  return request({
    url: `/api/achievement/list/category/${category}`,
    method: 'get'
  });
}

/**
 * 获取用户成就
 * @param params 查询参数
 * @returns Promise
 */
export function getUserAchievements(params?: any) {
  return request({
    url: '/api/achievement/user',
    method: 'get',
    params
  });
}

/**
 * 获取用户特定类别的成就
 * @param category 成就类别
 * @returns Promise
 */
export function getUserAchievementsByCategory(category: string) {
  return request({
    url: `/api/achievement/user/category/${category}`,
    method: 'get'
  });
}

/**
 * 更新用户成就显示状态
 * @param userAchievementId 用户成就ID
 * @param displayed 是否显示
 * @returns Promise
 */
export function updateUserAchievementDisplay(userAchievementId: number, displayed: boolean) {
  return request({
    url: `/api/achievement/user/${userAchievementId}/display/${displayed}`,
    method: 'put'
  });
}

/**
 * 领取成就积分奖励
 * @param userAchievementId 用户成就ID
 * @returns Promise
 */
export function claimAchievementPoints(userAchievementId: number) {
  return request({
    url: `/api/achievement/user/${userAchievementId}/claim`,
    method: 'post'
  });
}

/**
 * 添加成就
 * @param achievement 成就信息
 * @returns Promise
 */
export function addAchievement(achievement: any) {
  return request({
    url: '/api/achievement/admin',
    method: 'post',
    data: achievement
  });
}

/**
 * 更新成就
 * @param achievementId 成就ID
 * @param achievement 成就信息
 * @returns Promise
 */
export function updateAchievement(achievementId: number, achievement: any) {
  return request({
    url: `/api/achievement/admin/${achievementId}`,
    method: 'put',
    data: achievement
  });
}

/**
 * 删除成就
 * @param achievementId 成就ID
 * @returns Promise
 */
export function deleteAchievement(achievementId: number) {
  return request({
    url: `/api/achievement/admin/${achievementId}`,
    method: 'delete'
  });
}

/**
 * 获取成就详情
 * @param achievementId 成就ID
 * @returns Promise
 */
export function getAchievementById(achievementId: number) {
  return request({
    url: `/api/achievement/admin/${achievementId}`,
    method: 'get'
  });
}